Homology computation

Using dionysus we can compute homology. First we have to include necessary classes and define our complex. In our example we will compute the homology of a (empty) triangle.


In [1]:
from dionysus import Simplex, Filtration, StaticPersistence, \
                     vertex_cmp, data_cmp, data_dim_cmp, \
                     DynamicPersistenceChains

complex = [Simplex((0,),        0),                 # A
           Simplex((1,),        0),                 # B
           Simplex((2,),        0),                 # C
           Simplex((0,1),       0),                 # AB
           Simplex((1,2),       0),                 # BC
           Simplex((0,2),       0),                 # CA
]

Now we have to define a filtration. This is connected with persistent homology which is still a mistery to us at this time. So please just take this as a recipe.


In [2]:
f = Filtration(complex, data_cmp)            
p = DynamicPersistenceChains(f)
p.pair_simplices()
smap = p.make_simplex_map(f)

The homology has been computed. One can determine not only the number of generators but also the generating cycles. Let us print out the generators of the homology groups.


In [3]:
for i in [i for i in p if i.unpaired()]:
    print "Dim: {0}: {1}".format(smap[i].dimension(), 
                                [smap[ii] for ii in i.chain])


Dim: 0: [<0>]
Dim: 1: [<0, 2>, <1, 2>, <0, 1>]

In [ ]: